<div carousel-item="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label required">IP</label>
                    <div class="layui-input-block">
                        <input type="text" name="ipAddress" lay-verify="required" lay-reqtext="IP不能为空"
                               placeholder="请输入IP"
                               value="" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label required">开始时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="startTimeValue" id="startTimeValue" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label required">结束时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="endTimeValue" id="endTimeValue" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'common', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            common = layui.common
            , laydate = layui.laydate;
        $ = layui.$;

        //日期
        laydate.render({
            elem: '#startTimeValue'
            , type: 'datetime'
            , trigger: 'click'//呼出事件改成click
            //,format: 'yyyy-MM-dd HH:mm:ss' //可任意组合
        });
        laydate.render({
            elem: '#endTimeValue'
            , type: 'datetime'
            , trigger: 'click'//呼出事件改成click
        });

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            common.ajaxPost('/api/server/add',
                JSON.stringify(data.field)
                , function (_data) {
                    if (_data.resCode === '0000') {
                        layer.close(parentIndex);
                        layer.msg(_data.resDesc, {icon: 6});
                        table.reload('currentTableId');
                    } else {
                        layer.msg(_data.resDesc, {icon: 7});
                    }
                }
            )
            return false;
        });
    });
</script>

